﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Helper
{
   public class Time
    {
        /// <summary>
        /// Возвращает дату в MS без учета времени
        /// </summary>
        public static long GetDateInMS(DateTime d)
        {
            TimeSpan ts = (TimeSpan)(d.Date - Convert.ToDateTime("01.01.1970"));
            return (long)ts.TotalMilliseconds;
        }

        public static long GetDateInMS(string s)
        {
            DateTime d=DateTime .MinValue ;
            DateTime.TryParse (s,out d);
            if (d == DateTime.MinValue)
                return 0;

            TimeSpan ts = (TimeSpan)(d.Date - Convert.ToDateTime("01.01.1970"));
            return (long)ts.TotalMilliseconds;
        }


        /// <summary>
        /// Возвращает дату в MS с учетом времени
        /// </summary>
        public static long GetDateInMSWithHour(DateTime d)
        {
            TimeSpan ts = (TimeSpan)(d - Convert.ToDateTime("01.01.1970"));
            return (long)ts.TotalMilliseconds;
        }
        public static DateTime GetDatefromMS(long d)
        {

            return Convert.ToDateTime("01.01.1970").Date.AddMilliseconds(d);
        }
    }
}
